{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using the latest cached version of the module from /home/eecs/sijuntan/.cache/huggingface/modules/datasets_modules/datasets/gaia-benchmark--GAIA/ec492fe4320ee795b1aed6bb46229c5f693226b0f1316347501c24b4baeee005 (last modified on Tue Mar 25 22:55:51 2025) since it couldn't be found locally at gaia-benchmark/GAIA, or remotely on the Hugging Face Hub.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dataset({\n",
      "    features: ['task_id', 'Question', 'Level', 'Final answer', 'file_name', 'file_path', 'Annotator Metadata'],\n",
      "    num_rows: 301\n",
      "})\n",
      "len(ds): 301\n",
      "keys: dict_keys(['task_id', 'Question', 'Level', 'Final answer', 'file_name', 'file_path', 'Annotator Metadata'])\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "import os\n",
    "\n",
    "from datasets import load_dataset\n",
    "\n",
    "ds = load_dataset(\"gaia-benchmark/GAIA\", \"2023_all\", trust_remote_code=True, split=\"test\")\n",
    "print(ds)\n",
    "print(f\"len(ds): {len(ds)}\")\n",
    "print(f\"keys: {ds[0].keys()}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def process_datasets(ds):\n",
    "    dataset = []\n",
    "    for entry in ds:\n",
    "        task_id = entry[\"task_id\"]\n",
    "        problem = entry[\"Question\"]\n",
    "        tests = entry[\"Final answer\"]\n",
    "        file_name = entry[\"file_name\"]\n",
    "        new_entry = {\"task_id\": task_id, \"problem\": problem, \"tests\": tests, \"file_name\": file_name}\n",
    "        dataset.append(new_entry)\n",
    "    return dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "len(test_data): 301\n"
     ]
    }
   ],
   "source": [
    "test_dataset = process_datasets(ds)\n",
    "print(f\"len(test_data): {len(test_dataset)}\")\n",
    "output_dir = os.path.abspath(\"../../test/web\")\n",
    "output_file = os.path.join(output_dir, \"gaia.json\")\n",
    "\n",
    "with open(output_file, \"w\") as f:\n",
    "    json.dump(test_dataset, f, indent=4)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "rllm-xiao",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
